{
 "cells": [
  {
   "metadata": {},
   "cell_type": "markdown",
   "source": "# 拼接与分割",
   "id": "ee93cff96793c1db"
  },
  {
   "metadata": {
    "collapsed": true,
    "ExecuteTime": {
     "end_time": "2025-03-25T09:06:10.905155Z",
     "start_time": "2025-03-25T09:06:10.886424Z"
    }
   },
   "cell_type": "code",
   "source": [
    "import numpy as np\n",
    "\n",
    "a = np.array([[1, 2], [3, 4]])\n",
    "b = np.array([[5, 6], [7, 8]])\n",
    "print(np.concatenate((a, b), axis=0))\n",
    "print(np.concatenate((a, b), axis=1))\n"
   ],
   "id": "initial_id",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[1 2]\n",
      " [3 4]\n",
      " [5 6]\n",
      " [7 8]]\n",
      "[[1 2 5 6]\n",
      " [3 4 7 8]]\n"
     ]
    }
   ],
   "execution_count": 5
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-03-25T09:24:15.448284Z",
     "start_time": "2025-03-25T09:24:15.443640Z"
    }
   },
   "cell_type": "code",
   "source": [
    "t = np.arange(24).reshape(4, 6).astype(\"float\")\n",
    "\n",
    "t[1, 3:] = np.nan\n",
    "print(t)\n",
    "# print(t.shape[1])\n",
    "for i in range(t.shape[1]):\n",
    "    temp_col = t[:, i]\n",
    "\n",
    "    nan_num = np.count_nonzero(temp_col != temp_col)\n",
    "\n",
    "    if nan_num != 0:\n",
    "        temp_col_not_nan = temp_col[(temp_col == temp_col)]\n",
    "        temp_col[np.isnan(temp_col)]= np.mean(temp_col_not_nan)\n",
    "print(t)"
   ],
   "id": "4379eade947cd32f",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[ 0.  1.  2.  3.  4.  5.]\n",
      " [ 6.  7.  8. nan nan nan]\n",
      " [12. 13. 14. 15. 16. 17.]\n",
      " [18. 19. 20. 21. 22. 23.]]\n",
      "[[ 0.  1.  2.  3.  4.  5.]\n",
      " [ 6.  7.  8. 13. 14. 15.]\n",
      " [12. 13. 14. 15. 16. 17.]\n",
      " [18. 19. 20. 21. 22. 23.]]\n"
     ]
    }
   ],
   "execution_count": 26
  },
  {
   "metadata": {},
   "cell_type": "markdown",
   "source": "# 轴滚动",
   "id": "1e0533fa204a6928"
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-03-25T09:25:25.783293Z",
     "start_time": "2025-03-25T09:25:25.779096Z"
    }
   },
   "cell_type": "code",
   "source": [
    "t = np.ones((3,4,5,6))\n",
    "t1=np.rollaxis(t,2,0)\n",
    "t1.shape"
   ],
   "id": "59971e2bb8180cb2",
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(5, 3, 4, 6)"
      ]
     },
     "execution_count": 27,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "execution_count": 27
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
